package com.example.myapplication.activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.view.View;
import java.util.List;
import android.graphics.Path;
//getLeft() getTop()
public class MyView extends View {
    private PointF userLocation;
    private Paint userPaint; // 用户位置绘制画笔
    private List<PointF> pathPoints; // 导航路径点
    private Paint pathPaint; // 导航路径绘制画笔

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        // 初始化用户位置绘制画笔
        userPaint = new Paint();
        userPaint.setAntiAlias(true);
        userPaint.setColor(Color.RED);
        userPaint.setStyle(Paint.Style.FILL);

        // 初始化导航路径绘制画笔
        pathPaint = new Paint();
        pathPaint.setAntiAlias(true);
        pathPaint.setColor(Color.BLUE);
        pathPaint.setStyle(Paint.Style.STROKE);
        pathPaint.setStrokeWidth(5);
    }

    public void setUserLocation(PointF userLocation) {
        // 更新用户位置坐标
        // ...
        this.userLocation=userLocation;
        invalidate(); // 重绘视图
    }

    public void setNavigationPath(List<PointF> pathPoints) {
        // 更新导航路径点坐标
        // ...
        this.pathPoints=pathPoints;
        invalidate(); // 重绘视图
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 绘制用户位置
        if (userLocation != null) {
            // 在用户位置绘制点
            float userX = userLocation.x;
            float userY = userLocation.y;
            canvas.drawCircle(userX, userY, 10, userPaint);
        }

        // 绘制导航路径
        if (pathPoints != null && pathPoints.size() > 1) {
            Path path = new Path();
            PointF startPoint = pathPoints.get(0);
            path.moveTo(startPoint.x, startPoint.y);

            for (int i = 1; i < pathPoints.size(); i++) {
                PointF point = pathPoints.get(i);
                path.lineTo(point.x, point.y);
               // canvas.drawCircle(point.x, point.y, 10, pathPaint);
            }

            canvas.drawPath(path, pathPaint);
        }
    }
}


